package cn.liccshop.core.utils;

import cn.liccshop.core.entity.ShopGoodsAttr;
import cn.liccshop.core.entity.ShopProducts;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author LiCC
 * @program LiCCShop
 * @description 商品属性组合
 * @since 2019-04-26-11:37
 */
public class AttrOfProduct {
    private static List<ShopProducts> combinationOne(List<List<ShopGoodsAttr>> attributesOfAttrs){
        List<ShopGoodsAttr> attrs = attributesOfAttrs.get(0);
        List<ShopProducts> products = new ArrayList<>();
        for (int i = 0; i < attrs.size(); i++){
            products.add(new ShopProducts()
                    .setGoodsId(attrs.get(i).getGoodsId())
                    .setGoodsAttr(attrs.get(i).getId())
                    .setProductName(attrs.get(i).getAttrValue())
                    .setProductPrice(new BigDecimal(0.00))
                    .setProductNumber(0)
                    .setProductWarnNumber(0)
                    .setProductSort((1 + i)*10));
        }
        return products;
    }
    private static List<ShopProducts> combinationTow(List<List<ShopGoodsAttr>> attributesOfAttrs){
        List<ShopGoodsAttr> attrsFirst = attributesOfAttrs.get(0);
        List<ShopGoodsAttr> attrsSecond = attributesOfAttrs.get(1);
        List<ShopProducts> products = new ArrayList<>();
        int num = 1;
        for (int i = 0; i < attrsFirst.size(); i++){
            String attrIdFirst = attrsFirst.get(i).getId();
            String nameFirst = attrsFirst.get(i).getAttrValue();
            for (int j = 0; j < attrsSecond.size(); j++){
                String attrIdSecond = attrIdFirst+":"+attrsSecond.get(j).getId();
                String nameSecond = nameFirst+"-"+attrsSecond.get(j).getAttrValue();
                products.add(new ShopProducts()
                        .setGoodsId(attrsSecond.get(j).getGoodsId())
                        .setGoodsAttr(attrIdSecond)
                        .setProductName(nameSecond)
                        .setProductPrice(new BigDecimal(0.00))
                        .setProductNumber(0)
                        .setProductWarnNumber(0)
                        .setProductSort(num*10));
                num++;
            }
        }
        return products;
    }
    private static List<ShopProducts> combinationThree(List<List<ShopGoodsAttr>> attributesOfAttrs){
        List<ShopGoodsAttr> attrsFirst = attributesOfAttrs.get(0);
        List<ShopGoodsAttr> attrsSecond = attributesOfAttrs.get(1);
        List<ShopGoodsAttr> attrsThree = attributesOfAttrs.get(2);
        List<ShopProducts> products = new ArrayList<>();
        int num = 1;
        for (int i = 0; i < attrsFirst.size(); i++){
            String attrIdFirst = attrsFirst.get(i).getId();
            String nameFirst = attrsFirst.get(i).getAttrValue();
            for (int j = 0; j < attrsSecond.size(); j++){
                String attrIdSecond = attrIdFirst+":"+attrsSecond.get(j).getId();
                String nameSecond = nameFirst+"-"+attrsSecond.get(j).getAttrValue();
                for (int k = 0; k < attrsThree.size(); k++){
                    String attrIdThree = attrIdSecond+":"+attrsThree.get(k).getId();
                    String nameThree = nameSecond+"-"+attrsThree.get(k).getAttrValue();
                    products.add(new ShopProducts()
                            .setGoodsId(attrsThree.get(k).getGoodsId())
                            .setGoodsAttr(attrIdThree)
                            .setProductName(nameThree)
                            .setProductPrice(new BigDecimal(0.00))
                            .setProductNumber(0)
                            .setProductWarnNumber(0)
                            .setProductSort(num*10));
                    num++;
                }
            }
        }
        return products;
    }
    private static List<ShopProducts> combinationFour(List<List<ShopGoodsAttr>> attributesOfAttrs){
        List<ShopGoodsAttr> attrsFirst = attributesOfAttrs.get(0);
        List<ShopGoodsAttr> attrsSecond = attributesOfAttrs.get(1);
        List<ShopGoodsAttr> attrsThree = attributesOfAttrs.get(2);
        List<ShopGoodsAttr> attrsFour = attributesOfAttrs.get(3);
        List<ShopProducts> products = new ArrayList<>();
        int num = 1;
        for (int i = 0; i < attrsFirst.size(); i++){
            String attrIdFirst = attrsFirst.get(i).getId();
            String nameFirst = attrsFirst.get(i).getAttrValue();
            for (int j = 0; j < attrsSecond.size(); j++){
                String attrIdSecond = attrIdFirst+":"+attrsSecond.get(j).getId();
                String nameSecond = nameFirst+"-"+attrsSecond.get(j).getAttrValue();
                for (int k = 0; k < attrsThree.size(); k++){
                    String attrIdThree = attrIdSecond+":"+attrsThree.get(k).getId();
                    String nameThree = nameSecond+"-"+attrsThree.get(k).getAttrValue();
                    for (int t = 0; t < attrsFour.size(); t++){
                        String attrIdFour = attrIdThree+":"+attrsFour.get(t).getId();
                        String nameFour = nameThree+"-"+attrsFour.get(t).getAttrValue();
                        products.add(new ShopProducts()
                                .setGoodsId(attrsFour.get(t).getGoodsId())
                                .setGoodsAttr(attrIdFour)
                                .setProductName(nameFour)
                                .setProductPrice(new BigDecimal(0.00))
                                .setProductNumber(0)
                                .setProductWarnNumber(0)
                                .setProductSort(num*10));
                        num++;
                    }
                }
            }
        }
        return products;
    }
    private static List<ShopProducts> combinationFive(List<List<ShopGoodsAttr>> attributesOfAttrs){
        List<ShopGoodsAttr> attrsFirst = attributesOfAttrs.get(0);
        List<ShopGoodsAttr> attrsSecond = attributesOfAttrs.get(1);
        List<ShopGoodsAttr> attrsThree = attributesOfAttrs.get(2);
        List<ShopGoodsAttr> attrsFour = attributesOfAttrs.get(3);
        List<ShopGoodsAttr> attrsFive = attributesOfAttrs.get(4);
        List<ShopProducts> products = new ArrayList<>();
        int num = 1;
        for (int i = 0; i < attrsFirst.size(); i++){
            String attrIdFirst = attrsFirst.get(i).getId();
            String nameFirst = attrsFirst.get(i).getAttrValue();
            for (int j = 0; j < attrsSecond.size(); j++){
                String attrIdSecond = attrIdFirst+":"+attrsSecond.get(j).getId();
                String nameSecond = nameFirst+"-"+attrsSecond.get(j).getAttrValue();
                for (int k = 0; k < attrsThree.size(); k++){
                    String attrIdThree = attrIdSecond+":"+attrsThree.get(k).getId();
                    String nameThree = nameSecond+"-"+attrsThree.get(k).getAttrValue();
                    for (int t = 0; t < attrsFour.size(); t++){
                        String attrIdFour = attrIdThree+":"+attrsFour.get(t).getId();
                        String nameFour = nameThree+"-"+attrsFour.get(t).getAttrValue();
                        for (int y = 0; y < attrsFive.size(); y++){
                            String attrIdFive = attrIdFour+":"+attrsFive.get(y).getId();
                            String nameFive = nameFour+"-"+attrsFive.get(y).getAttrValue();
                            products.add(new ShopProducts()
                                    .setGoodsId(attrsFive.get(y).getGoodsId())
                                    .setGoodsAttr(attrIdFive)
                                    .setProductName(nameFive)
                                    .setProductPrice(new BigDecimal(0.00))
                                    .setProductNumber(0)
                                    .setProductWarnNumber(0)
                                    .setProductSort(num*10));
                            num++;
                        }
                    }
                }
            }
        }
        return products;
    }
    private static List<ShopProducts> combinationSix(List<List<ShopGoodsAttr>> attributesOfAttrs){
        List<ShopGoodsAttr> attrsFirst = attributesOfAttrs.get(0);
        List<ShopGoodsAttr> attrsSecond = attributesOfAttrs.get(1);
        List<ShopGoodsAttr> attrsThree = attributesOfAttrs.get(2);
        List<ShopGoodsAttr> attrsFour = attributesOfAttrs.get(3);
        List<ShopGoodsAttr> attrsFive = attributesOfAttrs.get(4);
        List<ShopGoodsAttr> attrsSix = attributesOfAttrs.get(5);
        List<ShopProducts> products = new ArrayList<>();
        int num = 1;
        for (int i = 0; i < attrsFirst.size(); i++){
            String attrIdFirst = attrsFirst.get(i).getId();
            String nameFirst = attrsFirst.get(i).getAttrValue();
            for (int j = 0; j < attrsSecond.size(); j++){
                String attrIdSecond = attrIdFirst+":"+attrsSecond.get(j).getId();
                String nameSecond = nameFirst+"-"+attrsSecond.get(j).getAttrValue();
                for (int k = 0; k < attrsThree.size(); k++){
                    String attrIdThree = attrIdSecond+":"+attrsThree.get(k).getId();
                    String nameThree = nameSecond+"-"+attrsThree.get(k).getAttrValue();
                    for (int t = 0; t < attrsFour.size(); t++){
                        String attrIdFour = attrIdThree+":"+attrsFour.get(t).getId();
                        String nameFour = nameThree+"-"+attrsFour.get(t).getAttrValue();
                        for (int y = 0; y < attrsFive.size(); y++){
                            String attrIdFive = attrIdFour+":"+attrsFive.get(y).getId();
                            String nameFive = nameFour+"-"+attrsFive.get(y).getAttrValue();
                            for (int f = 0; f < attrsSix.size(); f++){
                                String attrIdSix = attrIdFive+":"+attrsSix.get(f).getId();
                                String nameSix = nameFive+"-"+attrsSix.get(f).getAttrValue();
                                products.add(new ShopProducts()
                                        .setGoodsId(attrsSix.get(f).getGoodsId())
                                        .setProductPrice(new BigDecimal(0.00))
                                        .setGoodsAttr(attrIdSix)
                                        .setProductName(nameSix)
                                        .setProductSort(num*10));
                                num++;
                            }
                        }
                    }
                }
            }
        }
        return products;
    }
    public static List<ShopProducts> choose(List<List<ShopGoodsAttr>> attributesOfAttrs){
        int length = attributesOfAttrs.size();
        List<ShopProducts> products = new ArrayList<>();
        switch (length){
            case 1:
                products = combinationOne(attributesOfAttrs);
                break;
            case 2:
                products = combinationTow(attributesOfAttrs);
                break;
            case 3:
                products = combinationThree(attributesOfAttrs);
                break;
            case 4:
                products = combinationFour(attributesOfAttrs);
                break;
            case 5:
                products = combinationFive(attributesOfAttrs);
                break;
            case 6:
                products = combinationSix(attributesOfAttrs);
                break;
        }
        return products;
    }
}
